package com.aqie.easy.string;

/**
 * 520 检测大写字母
 * java 字符串 去除首字母
 */
public class DetectCapitalUse {
    public static boolean detectCapitalUse(String word) {
        char first = word.charAt(0);
        String rest= word.substring(1);
        if (isLower(first) && isAllLower(rest)){
            return true;
        }else if (isUpper(first) && isAllLower(rest)){
            return true;
        }else return isAllUpper(word);

    }

    private static boolean isAllLower(String word){
        for (int i = 0; i < word.length(); i++){
            if(isUpper(word.charAt(i))){
                return false;
            }
        }
        return true;
    }

    private static boolean isAllUpper(String word){
        for (int i = 0; i < word.length(); i++){
            if(isLower(word.charAt(i))){
                return false;
            }
        }
        return true;
    }

    private static boolean isUpper(char c){
        return c >= 'A' && c <= 'Z';
    }

    private static boolean isLower(char c){
        return c >= 'a' && c <= 'z';
    }

    public static void main(String[] args) {
        System.out.println((int)'a');   // 97
        System.out.println((int)'z');   // 122
        System.out.println((int)'A');   // 65
        System.out.println((int)'Z');   // 90

        System.out.println(detectCapitalUse("aUSA"));
    }
}
